home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / GNUPLOTsrc.lha / term / dumb.trm < prev    next >
Encoding:
Text File  |  1996-01-22  |  8.3 KB  |  363 lines

  1. /*
  2.  * $Id: dumb.trm,v 1.14 1995/12/20 21:47:43 drd Exp $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - dumb.trm */
  7. /*
  8.  * Copyright (C) 1991, 1992
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted,
  12.  * provided that the above copyright notice appear in all copies and
  13.  * that both that copyright notice and this permission notice appear
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed
  18.  * as patches to released version.
  19.  *
  20.  * This software  is provided "as is" without express or implied warranty.
  21.  *
  22.  * This file is included by ../term.c.
  23.  *
  24.  * This terminal driver supports:
  25.  *   DUMB terminals
  26.  *
  27.  * AUTHORS
  28.  *   Francois Pinard, 91-04-03
  29.  *           INTERNET: pinard@iro.umontreal.ca
  30.  *
  31.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  32.  *
  33.  */
  34. #ifndef GOT_DRIVER_H
  35. #include "driver.h"
  36. #endif
  37.  
  38. #ifdef TERM_REGISTER
  39. register_term(dumb_driver)
  40. #endif
  41.  
  42. #ifdef TERM_PROTO
  43. TERM_PUBLIC void DUMB_options __P((void));
  44. TERM_PUBLIC void DUMB_init __P((void));
  45. TERM_PUBLIC void DUMB_graphics __P((void));
  46. TERM_PUBLIC void DUMB_text __P((void));
  47. TERM_PUBLIC void DUMB_reset __P((void));
  48. TERM_PUBLIC void DUMB_linetype __P((int linetype));
  49. TERM_PUBLIC void DUMB_move __P((unsigned int x, unsigned int y));
  50. TERM_PUBLIC void DUMB_point __P((unsigned int x, unsigned int y, int point));
  51. TERM_PUBLIC void DUMB_vector __P((unsigned int x, unsigned int y));
  52. TERM_PUBLIC void DUMB_put_text __P((unsigned int x, unsigned int y, char *str));
  53. TERM_PUBLIC void DUMB_arrow __P((unsigned int sx, unsigned int sy, unsigned int ex, unsigned int ey, int head));
  54.  
  55. #define DUMB_XMAX 79
  56. #define DUMB_YMAX 24
  57.  
  58. #endif /* TERM_PROTO */
  59.  
  60. #ifdef TERM_BODY
  61.  
  62. #define DUMB_AXIS_CONST '\1'
  63. #define DUMB_BORDER_CONST '\2'
  64.  
  65. static char *dumb_matrix = NULL;      /* matrix of characters */
  66. static char *dumb_priority = NULL;    /* matrix of priority at each position */
  67. static char dumb_pen;                 /* current character used to draw */
  68. static int dumb_x;                    /* current X position */
  69. static int dumb_y;                    /* current Y position */
  70. static int dumb_xmax = DUMB_XMAX;
  71. static int dumb_ymax = DUMB_YMAX;
  72.  
  73. #define DUMB_PIXEL(x,y) dumb_matrix[dumb_xmax*(y)+(x)]
  74.  
  75. static void dumb_set_pixel __P((int x, int y, int v, int p));
  76.  
  77.  
  78. static void dumb_set_pixel(x,y,v,p)
  79. int x,y,v,p;
  80. {
  81.   if ( (unsigned) x <= dumb_xmax &&  /* ie x>=0 && x<=dumb_xmax */
  82.        (unsigned) y <= dumb_ymax &&
  83.        p > dumb_priority[dumb_xmax*y+x])
  84.     {
  85.       dumb_matrix[dumb_xmax*y+x] = v;
  86.       dumb_priority[dumb_xmax*y+x] = p;
  87.     }
  88. }
  89.  
  90.  
  91. TERM_PUBLIC void DUMB_options()
  92. {
  93.   int x,y;
  94.   struct value a;
  95.  
  96.   if (!END_OF_COMMAND) {
  97.     x = (int) real(const_express(&a));
  98.     if (!END_OF_COMMAND) {
  99.       y = (int) real(const_express(&a));
  100.       dumb_xmax = term->xmax = x;
  101.       dumb_ymax = term->ymax = y;
  102.     }
  103.   }
  104.  
  105.   sprintf(term_options, "%d %d",dumb_xmax,dumb_ymax);
  106. }
  107.  
  108.  
  109. TERM_PUBLIC void DUMB_init()
  110. {
  111.   if (dumb_matrix)
  112.     free(dumb_matrix);
  113.  
  114.   dumb_matrix = alloc ((unsigned long)dumb_xmax * dumb_ymax * 2, "dumb terminal");
  115.  
  116.   dumb_priority = dumb_matrix + dumb_xmax * dumb_ymax;
  117. }
  118.  
  119.  
  120. TERM_PUBLIC void DUMB_graphics ()
  121. {
  122.   int i;
  123.   char *pm = dumb_matrix, *pp = dumb_priority;
  124.  
  125.   for ( i = dumb_xmax * dumb_ymax; i > 0; i-- ) {
  126.     *pm++ = ' ';
  127.     *pp++ = 0;
  128.   }
  129. }
  130.  
  131.  
  132. TERM_PUBLIC void DUMB_text ()
  133. {
  134.   int x, y, l;
  135.  
  136.   putc ('\f', outfile);
  137.   for (y = dumb_ymax - 1; y >= 0; y--)
  138.     {
  139.       for (l = dumb_xmax; l > 0 && DUMB_PIXEL (l - 1, y) == ' '; l--)
  140.        ;
  141.       for (x = 0; x < l; x++)
  142.        putc (DUMB_PIXEL (x, y), outfile);
  143.       if (y>0) putc('\n', outfile);
  144.     }
  145.   fflush (outfile);
  146. }
  147.  
  148.  
  149. TERM_PUBLIC void DUMB_reset()
  150. {
  151.   free (dumb_matrix);
  152.   dumb_matrix = NULL;
  153. }
  154.  
  155.  
  156. TERM_PUBLIC void DUMB_linetype(linetype)
  157. int linetype;
  158. {
  159.   static char pen_type[7] = {'*', '#', '$', '%', '@', '&', '='};
  160.  
  161.   if (linetype == -2)
  162.     dumb_pen = DUMB_BORDER_CONST;
  163.   else if (linetype == -1)
  164.     dumb_pen = DUMB_AXIS_CONST;
  165.   else
  166.     {
  167.       linetype = linetype % 7;
  168.       dumb_pen = pen_type[linetype];
  169.     }
  170. }
  171.  
  172.  
  173. TERM_PUBLIC void DUMB_move(x, y)
  174. unsigned int x, y;
  175. {
  176.   dumb_x = x;
  177.   dumb_y = y;
  178. }
  179.  
  180.  
  181. TERM_PUBLIC void DUMB_point(x,y,point)
  182. unsigned int x,y;
  183. int point;
  184. {
  185.   dumb_set_pixel (x, y, point == -1 ? '.' : point % 26 + 'A', 4);
  186. }
  187.  
  188.  
  189. TERM_PUBLIC void DUMB_vector(_x,_y)
  190. unsigned int _x,_y;
  191. {
  192.   int x=_x;    /* we need signed int, since unsigned-signed=unsigned and */
  193.   int y=_y;    /* abs and cast to double wouldn't work */
  194.   char pen, pen1;
  195.   int priority;
  196.   int delta;
  197.  
  198.   if (abs (y - dumb_y) > abs (x - dumb_x))
  199.     {
  200.       switch (dumb_pen)
  201.        {
  202.        case DUMB_AXIS_CONST:
  203.          pen = ':';
  204.          pen1 = '+';
  205.          priority = 1;
  206.          break;
  207.  
  208.        case DUMB_BORDER_CONST:
  209.          pen = '|';
  210.          pen1 = '+';
  211.          priority = 2;
  212.          break;
  213.  
  214.        default:
  215.          pen = dumb_pen;
  216.          pen1 = dumb_pen;
  217.          priority = 3;
  218.          break;
  219.        }
  220.       dumb_set_pixel (dumb_x, dumb_y, pen1, priority);
  221.       for (delta = 1; delta < abs (y - dumb_y); delta++)
  222.        dumb_set_pixel (dumb_x
  223.                        + (int) ((double) (x - dumb_x) * delta / abs(y - dumb_y)
  224.                                 + 0.5),
  225.                        dumb_y + delta * sign (y - dumb_y),
  226.                        pen, priority);
  227.       dumb_set_pixel (x, y, pen1, priority);
  228.     }
  229.   else if (abs (x - dumb_x) > abs (y - dumb_y))
  230.     {
  231.       switch (dumb_pen)
  232.        {
  233.        case DUMB_AXIS_CONST:
  234.          pen = '.';
  235.          pen1 = '+';
  236.          priority = 1;
  237.          break;
  238.  
  239.        case DUMB_BORDER_CONST:
  240.          pen = '-';
  241.          pen1 = '+';
  242.          priority = 2;
  243.          break;
  244.  
  245.        default:
  246.          pen = dumb_pen;
  247.          pen1 = dumb_pen;
  248.          priority = 3;
  249.          break;
  250.        }
  251.       dumb_set_pixel (dumb_x, dumb_y, pen1, priority);
  252.       for (delta = 1; delta < abs (x - dumb_x); delta++)
  253.        dumb_set_pixel (dumb_x + delta * sign (x - dumb_x),
  254.                        dumb_y +
  255.                        (int) ((double) (y - dumb_y) * delta / abs(x - dumb_x)
  256.                               + 0.5),
  257.                        pen, priority);
  258.       dumb_set_pixel (x, y, pen1, priority);
  259.     }
  260.   else
  261.     {
  262.       switch (dumb_pen)
  263.        {
  264.        case DUMB_AXIS_CONST:    /* zero length axis */
  265.          pen = '+';
  266.          priority = 1;
  267.          break;
  268.  
  269.        case DUMB_BORDER_CONST:    /* zero length border */
  270.          pen = '+';
  271.          priority = 2;
  272.          break;
  273.  
  274.        default:
  275.          pen = dumb_pen;
  276.          priority = 3;
  277.          break;
  278.        }
  279.       for (delta = 0; delta <= abs (x - dumb_x); delta++)
  280.     dumb_set_pixel (dumb_x + delta * sign (x - dumb_x),
  281.             dumb_y + delta * sign (y - dumb_y),
  282.             pen, priority);
  283.     }
  284.   dumb_x = x;
  285.   dumb_y = y;
  286. }
  287.  
  288.  
  289. TERM_PUBLIC void DUMB_put_text(x,y,str)
  290. unsigned int x, y;
  291. char *str;
  292. {
  293.   int length;
  294.  
  295.   length = strlen(str);
  296.   if (x + length > dumb_xmax)
  297.     x = max (0, dumb_xmax - length);
  298.  
  299.   for (; x < dumb_xmax && *str; x++, str++)
  300.     dumb_set_pixel (x, y, *str, 5);
  301. }
  302.  
  303.  
  304. TERM_PUBLIC void DUMB_arrow (sx,sy,ex,ey,head)
  305. unsigned int sx,sy,ex,ey;
  306. int head; /* ignored */
  307. {
  308.   char saved_pen;
  309.   char saved_x;
  310.   char saved_y;
  311.  
  312.   saved_pen = dumb_pen;
  313.   saved_x = dumb_x;
  314.   saved_y = dumb_y;
  315.  
  316.   dumb_pen = '>';
  317.   dumb_x = sx;
  318.   dumb_y = sy;
  319.   DUMB_vector (ex,ey);
  320.  
  321.   dumb_pen = saved_pen;
  322.   dumb_x = saved_x;
  323.   dumb_y = saved_y;
  324. }
  325. #endif /* TERM_BODY */
  326.  
  327. #ifdef TERM_TABLE
  328. TERM_TABLE_START(dumb_driver)
  329.          "dumb", "printer or glass dumb terminal",
  330.          DUMB_XMAX, DUMB_YMAX, 1, 1,
  331.          1, 1, DUMB_options, DUMB_init, DUMB_reset,
  332.          DUMB_text, null_scale, DUMB_graphics, DUMB_move, DUMB_vector,
  333.          DUMB_linetype, DUMB_put_text, null_text_angle,
  334.          null_justify_text, DUMB_point, DUMB_arrow, set_font_null,
  335.             0, /* pointsize */
  336.             TERM_CAN_MULTIPLOT
  337. TERM_TABLE_END(dumb_driver)
  338.  
  339. #undef LAST_TERM
  340. #define LAST_TERM dumb_driver
  341.  
  342. #endif /* TERM_TABLE */
  343.  
  344.  
  345. #ifdef TERM_HELP
  346. START_HELP(dumb)
  347. "1 dumb",
  348. "?set terminal dumb",
  349. "?dumb",
  350. " The dumb terminal driver has an optional size specification.",
  351. "",
  352. " Syntax:",
  353. "         set terminal dumb {<xsize> <ysize>}",
  354. "",
  355. " where <xsize> and <ysize> set the size of the dumb terminals. Default is",
  356. " 79 by 24.",
  357. "",
  358. " Examples:",
  359. "         set term dumb",
  360. "         set term dumb 79 49 # VGA screen---why would anyone want to do that?"
  361. END_HELP(dumb)
  362. #endif
  363.